// src/model/word.ts
export class Word {
  id: string = '';
  word: string = '';
  phonetic: string = '';
  translation: string = '';
  example: string = '';
  image: string = '';
  category: string = '';
  difficulty: number = 1; // 1-5级
  lastReviewTime: number = 0;
  nextReviewTime: number = 0;
  reviewCount: number = 0;
  correctCount: number = 0;
  isMastered: boolean = false;
}

// 简单打乱数组
export function shuffleWords<T>(items: T[]): T[] {
  const arr = items.slice();
  for (let i = arr.length - 1; i > 0; i--) {
    const j = Math.floor(Math.random() * (i + 1));
    const temp = arr[i];
    arr[i] = arr[j];
    arr[j] = temp;
  }
  return arr;
}

// 生成默认的较大单词集（示例数据，可按需扩展/替换为服务端）
export function getSeedWords(): Word[] {
  const list: Word[] = [
    { id: '1', word: 'apple', phonetic: '/ˈæp.əl/', translation: '苹果', example: 'I eat an apple every day.', image: '', category: 'fruit', difficulty: 1, lastReviewTime: 0, nextReviewTime: 0, reviewCount: 0, correctCount: 0, isMastered: false },
    { id: '2', word: 'beautiful', phonetic: '/ˈbjuː.tɪ.fəl/', translation: '美丽的', example: 'She has a beautiful voice.', image: '', category: 'adjective', difficulty: 2, lastReviewTime: 0, nextReviewTime: 0, reviewCount: 0, correctCount: 0, isMastered: false },
    { id: '3', word: 'computer', phonetic: '/kəmˈpjuː.tər/', translation: '计算机', example: 'I use my computer to work.', image: '', category: 'technology', difficulty: 2, lastReviewTime: 0, nextReviewTime: 0, reviewCount: 0, correctCount: 0, isMastered: false },
    { id: '4', word: 'banana', phonetic: '/bəˈnɑː.nə/', translation: '香蕉', example: 'Bananas are rich in potassium.', image: '', category: 'fruit', difficulty: 1, lastReviewTime: 0, nextReviewTime: 0, reviewCount: 0, correctCount: 0, isMastered: false },
    { id: '5', word: 'library', phonetic: '/ˈlaɪ.brer.i/', translation: '图书馆', example: 'I study at the library.', image: '', category: 'place', difficulty: 1, lastReviewTime: 0, nextReviewTime: 0, reviewCount: 0, correctCount: 0, isMastered: false },
    { id: '6', word: 'mountain', phonetic: '/ˈmaʊn.tɪn/', translation: '山', example: 'They climbed the mountain.', image: '', category: 'nature', difficulty: 2, lastReviewTime: 0, nextReviewTime: 0, reviewCount: 0, correctCount: 0, isMastered: false },
    { id: '7', word: 'river', phonetic: '/ˈrɪv.ər/', translation: '河流', example: 'The river flows to the sea.', image: '', category: 'nature', difficulty: 1, lastReviewTime: 0, nextReviewTime: 0, reviewCount: 0, correctCount: 0, isMastered: false },
    { id: '8', word: 'education', phonetic: '/ˌedʒ.ʊˈkeɪ.ʃən/', translation: '教育', example: 'Education changes lives.', image: '', category: 'abstract', difficulty: 3, lastReviewTime: 0, nextReviewTime: 0, reviewCount: 0, correctCount: 0, isMastered: false },
    { id: '9', word: 'language', phonetic: '/ˈlæŋ.ɡwɪdʒ/', translation: '语言', example: 'Language connects people.', image: '', category: 'abstract', difficulty: 2, lastReviewTime: 0, nextReviewTime: 0, reviewCount: 0, correctCount: 0, isMastered: false },
    { id: '10', word: 'music', phonetic: '/ˈmjuː.zɪk/', translation: '音乐', example: 'Music soothes the soul.', image: '', category: 'art', difficulty: 1, lastReviewTime: 0, nextReviewTime: 0, reviewCount: 0, correctCount: 0, isMastered: false },
    { id: '11', word: 'engineer', phonetic: '/ˌen.dʒɪˈnɪər/', translation: '工程师', example: 'He works as an engineer.', image: '', category: 'job', difficulty: 2, lastReviewTime: 0, nextReviewTime: 0, reviewCount: 0, correctCount: 0, isMastered: false },
    { id: '12', word: 'hospital', phonetic: '/ˈhɒs.pɪ.təl/', translation: '医院', example: 'The hospital is nearby.', image: '', category: 'place', difficulty: 1, lastReviewTime: 0, nextReviewTime: 0, reviewCount: 0, correctCount: 0, isMastered: false },
    { id: '13', word: 'delicious', phonetic: '/dɪˈlɪʃ.əs/', translation: '美味的', example: 'The cake is delicious.', image: '', category: 'adjective', difficulty: 1, lastReviewTime: 0, nextReviewTime: 0, reviewCount: 0, correctCount: 0, isMastered: false },
    { id: '14', word: 'wisdom', phonetic: '/ˈwɪz.dəm/', translation: '智慧', example: 'Age brings wisdom.', image: '', category: 'abstract', difficulty: 3, lastReviewTime: 0, nextReviewTime: 0, reviewCount: 0, correctCount: 0, isMastered: false },
    { id: '15', word: 'forest', phonetic: '/ˈfɒr.ɪst/', translation: '森林', example: 'Animals live in the forest.', image: '', category: 'nature', difficulty: 1, lastReviewTime: 0, nextReviewTime: 0, reviewCount: 0, correctCount: 0, isMastered: false },
    { id: '16', word: 'architecture', phonetic: '/ˈɑː.kɪ.tek.tʃər/', translation: '建筑学；建筑风格', example: 'The city is famous for its architecture.', image: '', category: 'abstract', difficulty: 4, lastReviewTime: 0, nextReviewTime: 0, reviewCount: 0, correctCount: 0, isMastered: false },
    { id: '17', word: 'courage', phonetic: '/ˈkʌr.ɪdʒ/', translation: '勇气', example: 'He showed great courage.', image: '', category: 'abstract', difficulty: 2, lastReviewTime: 0, nextReviewTime: 0, reviewCount: 0, correctCount: 0, isMastered: false },
    { id: '18', word: 'economy', phonetic: '/ɪˈkɒn.ə.mi/', translation: '经济', example: 'The economy is improving.', image: '', category: 'abstract', difficulty: 3, lastReviewTime: 0, nextReviewTime: 0, reviewCount: 0, correctCount: 0, isMastered: false },
    { id: '19', word: 'festival', phonetic: '/ˈfes.tɪ.vəl/', translation: '节日；庆典', example: 'The festival lasts three days.', image: '', category: 'culture', difficulty: 1, lastReviewTime: 0, nextReviewTime: 0, reviewCount: 0, correctCount: 0, isMastered: false },
    { id: '20', word: 'generate', phonetic: '/ˈdʒen.ə.reɪt/', translation: '产生；生成', example: 'Solar panels generate electricity.', image: '', category: 'verb', difficulty: 3, lastReviewTime: 0, nextReviewTime: 0, reviewCount: 0, correctCount: 0, isMastered: false },
    { id: '21', word: 'harmony', phonetic: '/ˈhɑː.mə.ni/', translation: '和谐', example: 'They live in harmony.', image: '', category: 'abstract', difficulty: 2, lastReviewTime: 0, nextReviewTime: 0, reviewCount: 0, correctCount: 0, isMastered: false },
    { id: '22', word: 'innovate', phonetic: '/ˈɪn.ə.veɪt/', translation: '创新', example: 'We need to innovate constantly.', image: '', category: 'verb', difficulty: 3, lastReviewTime: 0, nextReviewTime: 0, reviewCount: 0, correctCount: 0, isMastered: false },
    { id: '23', word: 'journey', phonetic: '/ˈdʒɜː.ni/', translation: '旅行；旅程', example: 'The journey was long.', image: '', category: 'noun', difficulty: 1, lastReviewTime: 0, nextReviewTime: 0, reviewCount: 0, correctCount: 0, isMastered: false },
    { id: '24', word: 'knowledge', phonetic: '/ˈnɒl.ɪdʒ/', translation: '知识', example: 'Reading increases knowledge.', image: '', category: 'abstract', difficulty: 2, lastReviewTime: 0, nextReviewTime: 0, reviewCount: 0, correctCount: 0, isMastered: false },
    { id: '25', word: 'landscape', phonetic: '/ˈlænd.skeɪp/', translation: '风景；地貌', example: 'The landscape is breathtaking.', image: '', category: 'nature', difficulty: 2, lastReviewTime: 0, nextReviewTime: 0, reviewCount: 0, correctCount: 0, isMastered: false },
    { id: '26', word: 'motivate', phonetic: '/ˈməʊ.tɪ.veɪt/', translation: '激励', example: 'A good leader can motivate the team.', image: '', category: 'verb', difficulty: 2, lastReviewTime: 0, nextReviewTime: 0, reviewCount: 0, correctCount: 0, isMastered: false },
    { id: '27', word: 'network', phonetic: '/ˈnet.wɜːk/', translation: '网络', example: 'The devices are connected to the network.', image: '', category: 'technology', difficulty: 2, lastReviewTime: 0, nextReviewTime: 0, reviewCount: 0, correctCount: 0, isMastered: false },
    { id: '28', word: 'optimize', phonetic: '/ˈɒp.tɪ.maɪz/', translation: '优化', example: 'We should optimize the code.', image: '', category: 'technology', difficulty: 3, lastReviewTime: 0, nextReviewTime: 0, reviewCount: 0, correctCount: 0, isMastered: false },
    { id: '29', word: 'photograph', phonetic: '/ˈfəʊ.tə.ɡrɑːf/', translation: '照片', example: 'She took a beautiful photograph.', image: '', category: 'noun', difficulty: 2, lastReviewTime: 0, nextReviewTime: 0, reviewCount: 0, correctCount: 0, isMastered: false },
    { id: '30', word: 'quality', phonetic: '/ˈkwɒl.ə.ti/', translation: '质量', example: 'Quality matters more than quantity.', image: '', category: 'noun', difficulty: 2, lastReviewTime: 0, nextReviewTime: 0, reviewCount: 0, correctCount: 0, isMastered: false }
  ];
  return list;
}

// 从词库中挑选干扰项（不包含当前单词）
export function pickDistractorTranslations(words: Word[], correctWordId: string, count: number): string[] {
  const pool = words.filter(w => w.id !== correctWordId).map(w => w.translation);
  const shuffled = shuffleWords(pool);
  return shuffled.slice(0, Math.max(0, Math.min(count, shuffled.length)));
}